<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="com.is.util.ParamUtil"%>
<%@page import="com.is.util.DesData"%>
<%@page import="com.is.model.Student"%>
<%@page import="com.is.control.StudentControl"%>
<%@page import="com.is.util.DateTime"%>
<%@page import="com.is.control.ParamStuyearControl"%>
<%@page import="com.is.control.AttendanceDetailControl"%>
<%@page import="java.util.List"%>
<%@page import="com.is.model.CourseClass"%>
<%@page import="com.is.control.CourseClassControl"%>
<%@page import="com.is.control.ParamCourseControl"%>
<%@page import="com.is.control.DictationControl"%>
<%@page import="com.is.control.HomeworkControl"%>
<%@page import="com.is.model.ParamStuyear"%>
<%@page import="com.is.model.CourseScore"%>
<%@page import="com.is.control.CourseScoreControl"%>
<%@page import="com.is.control.AttendanceTimeControl"%>
<%@page import="com.is.control.DictationTimeControl"%>
<%@page import="com.is.control.HomeworkTimeControl"%>
<%@page import="com.is.model.ParamCourseScoreGS"%>
<%@page import="com.is.control.ParamCourseScoreGSControl"%>
<%@page import="com.is.model.ParamReasonType"%>
<%@page import="com.is.control.ParamReasonTypeControl"%>
<%@page import="com.is.control.ParamReasonTypeGSControl"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="shortcut icon" href="/InterStu/resources/image/favicon.ico" />
<script type="text/javascript" src="resources/js/jquery-1.8.1.js"></script>
<link rel="stylesheet" type="text/css" href="resources/css/common.css"/>
<link rel="stylesheet" type="text/css" href="resources/css/student.css"/>
<script type="text/javascript" src="resources/js/WebCalendar.js"></script>
<style type="text/css">
	
</style>
<title>学生查询页面</title>
</head>
<body>
<%
         DesData des = new DesData();
         int stuId = Integer.parseInt(des.decrypt(ParamUtil.getString(request,"stuId","4d3d3f222d4c6e08")));
         String time1 = DateTime.SimpleDate();
    	 String time2 = DateTime.SimpleDate();
         int courseClassId = ParamUtil.getInt(request,"courseClassId",0);
         CourseClass usingCc = new CourseClass();
         ParamStuyear usingStuyear = ParamStuyearControl.getCurrentStuyear();
         int cy = usingStuyear.getId();
         if(courseClassId!=0){
        	    usingCc = CourseClassControl.getCourseClassById(courseClassId);
                usingStuyear = ParamStuyearControl.getStuyear(usingCc.getStuyear());
                cy=usingStuyear.getId();
                time1 = usingStuyear.getStartTime();
                time2= usingStuyear.getEndTime();
         }
         if(cy==ParamStuyearControl.getCurrentStuyearId()){
              time1 = usingStuyear.getStartTime();
	    	  time2 = DateTime.SimpleDate();
	     }
  	   
         if(stuId>0){
        	 Student s = StudentControl.getStudent(stuId);
         %>
          <%
        	      List<CourseClass> ccs = CourseClassControl.getAllCourseClassIdByClassIdAndStuyear(Integer.parseInt(s.getClassId()),0);
        	      if(ccs.size()>0){%>
			        	 <form action="studentResult.jsp" method="post">
			        	 <table class="table">
			        	 <tr class="odd">
			        	 <td>选择课程&nbsp;&nbsp;&nbsp;&nbsp;
			        	 <select name="courseClassId">
			        	<option value="0">-选择课程-</option>
			        	<%
					        	      for(CourseClass cc:ccs){
					        	 %>
					        	 <option value="<%=cc.getId() %>" <%if(cc.getId()==courseClassId) out.print("selected='selected'"); %>><%=ParamCourseControl.getCourseById(cc.getCourseId()).getCourseName() %></option>
					        	 <%} %>
					        	 </select>
					        	 </td>
			        	 <td>开始时间&nbsp;&nbsp;&nbsp;&nbsp;<input id="time1" type='text'  name="time1" <% if(cy==ParamStuyearControl.getCurrentStuyearId()){ %> onclick="SelectDate(this,'','','yyyy-MM-dd')"   style="cursor:pointer" <%} %>readonly  value="<%=time1 %>"/></td>
			             <td>结束时间&nbsp;&nbsp;&nbsp;&nbsp;<input id="time2" type='text'  name="time2" <% if(cy==ParamStuyearControl.getCurrentStuyearId()){ %> onclick="SelectDate(this,'','','yyyy-MM-dd')"   style="cursor:pointer" <%} %> readonly  value="<%=time2 %>"/></td>
			        	<td><input type="hidden" name="stuId" value="<%=des.encrypt(String.valueOf(stuId)) %>"><input type="submit" value="确认" /></td>
			        	</tr>
			        	</table>
			        	</form>
			        	 <%
						            if(courseClassId>0){
								        	System.out.print(courseClassId);
							        	   CourseClass nowcc  = CourseClassControl.getCourseClassById(courseClassId); 
							        	   CourseScore cs = CourseScoreControl.getCSByStuIdAndCourseId(courseClassId,s.getId());
							        	   ParamCourseScoreGS gs = ParamCourseScoreGSControl.getGSByCourseClassId(courseClassId);
						        	       List<ParamReasonType> types = ParamReasonTypeControl.getAllReaons();
						        	       StringBuffer sb = new StringBuffer();
						        	       for(ParamReasonType prt:types){
						        	    	   if(prt.getId()!=1&&prt.getId()!=3){  //此处以缺勤为单位1
						        	    		   sb.append(prt.getReasonType()+ParamReasonTypeGSControl.getNumByTypeAndStuyear(prt.getId(),cy)+"次=");
						        	    	   }
						        	       }
							        	       sb.append("缺勤1次");
							        	 
							        	 
						            	 int CQ_CD=AttendanceDetailControl.getCount(2,s.getId(),courseClassId+"",cy,time1,time2);
							        	 int CQ_QQ = AttendanceDetailControl.getCount(3,s.getId(),courseClassId+"",cy,time1,time2);
							        	 int CQ_BJ = AttendanceDetailControl.getCount(4,s.getId(),courseClassId+"",cy,time1,time2);
							        	 int CQ_SJ = AttendanceDetailControl.getCount(5,s.getId(),courseClassId+"",cy,time1,time2);
							        	// float totalQQ= (float)CQ_CD/3+(float)CQ_BJ/2+CQ_SJ+CQ_QQ; 
							        	 
							        	  float totalQQ=0;
						        		  boolean flag = true;
								          int count2 = AttendanceDetailControl.getCount(2,s.getId(),courseClassId+"",cy,time1,time2);
								          int num2 = ParamReasonTypeGSControl.getNumByTypeAndStuyear(2,cy);
								          if(num2==0){
								        	  flag = false;
								          }else{
								        	  totalQQ+= (float)count2/num2;
								          }
								          int count3 = AttendanceDetailControl.getCount(3,s.getId(),courseClassId+"",cy,time1,time2);
								          int num3 = ParamReasonTypeGSControl.getNumByTypeAndStuyear(3,cy);
								          if(num3==0){
								        	  flag = false;
								          }else{
								        	  totalQQ+= (float)count3/num3;
								          }
								          int count4 =AttendanceDetailControl.getCount(4,s.getId(),courseClassId+"",cy,time1,time2);
								          int num4 =ParamReasonTypeGSControl.getNumByTypeAndStuyear(4,cy);
								          if(num4==0){
								        	  flag = false;
								          }else{
								        	  totalQQ+= (float)count4/num4;
								          }
								          int count5 = AttendanceDetailControl.getCount(5,s.getId(),courseClassId+"",cy,time1,time2);
								          int num5 = ParamReasonTypeGSControl.getNumByTypeAndStuyear(5,cy);
								          if(num5==0){
								        	  flag = false;
								          }else{
								        	  totalQQ+= (float)count5/num5;
								          }
							        	 
							        	 
							        	 int TX_A = DictationControl.getCount(s.getId(),"A",courseClassId,cy,time1,time2);
							        	 int TX_B = DictationControl.getCount(s.getId(),"B",courseClassId,cy,time1,time2);
							        	 int TX_C = DictationControl.getCount(s.getId(),"C",courseClassId,cy,time1,time2);
							        	 int TX_D = DictationControl.getCount(s.getId(),"D",courseClassId,cy,time1,time2);
							        	 
							        	 int ZY_A = HomeworkControl.getCount(s.getId(),"A",courseClassId,cy,time1,time2);
							        	 int ZY_B = HomeworkControl.getCount(s.getId(),"B",courseClassId,cy,time1,time2);
							        	 int ZY_C = HomeworkControl.getCount(s.getId(),"C",courseClassId,cy,time1,time2);
							        	 int ZY_D = HomeworkControl.getCount(s.getId(),"D",courseClassId,cy,time1,time2);
							        	 
							        	String daily = cs!=null?cs.getDailyScore():"暂无数据";
							        	String mid = cs!=null?cs.getMidtermScore():"暂无数据";
							        	String finalS = cs!=null?cs.getFinalScore():"暂无数据";
							        	String total = cs!=null?cs.getTotalScore():"暂无数据";
							        	 
							        	 %>
							        	 <form>
							        	 <fieldset>
							        	 
							        	 <p class="name"><%=s.getChineseName() %>在<%=ParamCourseControl.getCourseById(nowcc.getCourseId()).getCourseName() %>上的相关表现</p>
							        	 <table class="table">
							        	  <caption>出勤情况【共点名<%=AttendanceTimeControl.getCount(courseClassId,cy,"","") %>次】【<%=flag?sb:"Error" %>】</caption>
							        	 <tr>
							        	 <th width="20%">迟到(/次)</th>
							        	 <th width="20%">缺勤(/次)</th>
							        	 <th width="20%">病假(/次)</th>
							        	 <th width="20%">事假(/次)</th>
							        	 <th>折合为缺勤次数</th>
							        	 </tr>
							        	 <tr>
							        	 <td><img src="resources/icons/a.gif"/> x <%=flag?count2:"Error" %></td>
							        	 <td><img src="resources/icons/b.gif"/> x <%=flag?count3:"Error"%></td>
							        	 <td><img src="resources/icons/c.gif"/> x <%=flag?count4:"Error" %></td>
							        	 <td><img src="resources/icons/d.gif"/> x <%=flag?count5:"Error" %></td>
							        	  <td><img src="resources/icons/e.gif"/> x <%=flag?totalQQ:"Error" %></td>
							        	 </tr>
							        	 </table>
							        	 
							        	  <table class="table">
							        	 <caption>听写情况【共听写<%=DictationTimeControl.getCount(courseClassId,cy,"","") %>次】</caption>
							        	 <tr>
							        	 <th>A(/次)</th>
							        	 <th>B(/次)</th>
							        	 <th>C(/次)</th>
							        	 <th>D(/次)</th>
							        	 </tr>
							        	 <tr>
							        	 <td><img src="resources/icons/1.gif"/> x <%=TX_A %></td>
							        	 <td><img src="resources/icons/2.gif"/> x <%=TX_B %></td>
							        	 <td><img src="resources/icons/3.gif"/> x <%=TX_C %></td>
							        	 <td><img src="resources/icons/4.gif"/> x <%=TX_D %></td>
							        	 </tr>
							        	 </table>
							        	  <table class="table">
							        	  <caption>作业【共收阅<%=HomeworkTimeControl.getCount(courseClassId,cy,"","") %>次】</caption>
							        	 <tr>
							        	 <th>A(/次)</th>
							        	 <th>B(/次)</th>
							        	 <th>C(/次)</th>
							        	 <th>D(/次)</th>
							        	 </tr>
							        	 <tr>
							        	 <td><img src="resources/icons/1.gif"/> x <%=ZY_A %></td>
							        	 <td><img src="resources/icons/2.gif"/> x <%=ZY_B %></td>
							        	 <td><img src="resources/icons/3.gif"/> x <%=ZY_C %></td>
							        	 <td><img src="resources/icons/4.gif"/> x <%=ZY_D %></td>
							        	 </tr>
							        	 </table>
							        	 <table class="table">
							        	  <caption>成绩<%if(gs!=null){ %>【总成绩=平时(<%=gs.getDailyScore_per()+"%" %>)+期中(<%=gs.getMiderScore_per() +"%"%>)+期末(<%=gs.getFinalScore_per() +"%"%>)】<%} %></caption>
							        	 <tr>
							        	 <th>平时成绩</th>
							        	 <th>期中成绩</th>
							        	 <th>期末成绩</th>
							        	 <th>总成绩</th>
							        	 </tr>
							        	 <tr>
							        	 <td><%=daily %></td>
							        	 <td><%=mid %></td>
							        	 <td><%=finalS %></td>
							        	 <td><%=total %></td>
							        	 </tr>
							        	 </table>
							        	 </fieldset>
							        	 </form>
		        	 <%
						         }else{
						        	 out.print("<table class='table'><tr><td>请选择一门课程以查看详细情况</td></tr></table>");
						         }
        	     }else{
                	 out.print("<table class='table'><tr><td>抱歉，我们尚未找到该学生的相关课程信息</td></tr></table>");
                 }
         }else{
        	 out.print("<table class='table'><tr><td>抱歉，没有找到该学生的相关信息,请确认操作是否有误</td></tr></table>");
         }           
        	   
%>
<br/><br/><br/><br/><br/>
</body>
</html>